package router

import (
	"air_chat/common/middleware"
	"air_chat/internal/service"
	"air_chat/internal/service/customer"
	"net/http"

	_ "net/http/pprof"

	"github.com/gin-gonic/gin"

	_ "air_chat/docs" // swag init 产生的 docs

	swaggerfiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"
)

func Router() *gin.Engine {
	// r := gin.Default()
	r := gin.New()
	r.Use(gin.Recovery())
	r.Use(middleware.CorsMiddleware(), middleware.GinLogMiddleware())
	// 配置路由

	r.GET("/swagger-ui/*any", ginSwagger.WrapHandler(swaggerfiles.Handler))
	// r.GET("/ping", middleware.AuthMiddleware(), service.PingServer)
	r.GET("/ping", service.PingServer)
	// 注册 pprof 路由
	r.GET("/debug/pprof/*any", gin.WrapH(http.DefaultServeMux))

	customerRouter := r.Group("/customer")
	{
		customerRouter.POST("/register", customer.Register)
		customerRouter.POST("/login", customer.Login)

		customerRouter.GET("/send_msg", customer.SendMsg)
		customerRouter.GET("/chat", customer.ImChat)

	}
	return r
}
